﻿<%@ Page Language="C#" MasterPageFile="~/NestedMasterPage.master" EnableEventValidation="false" %>

<%@ Register TagPrefix="Page" TagName="Nav" Src="~/UserControls/PageControl.ascx" %>

<%@ Import Namespace="System.Web.Script.Serialization" %>


<script runat="server">
  List<PickOutRG> li;
  string Prod_Cat_ID = System.Configuration.ConfigurationManager.AppSettings["RedGreen"].ToString();
  protected void Page_Load(object sender, EventArgs e)
  {
    //建立已選購紅配綠商品
    if (Session["PickOutRG"] == null)
    {
      li = new List<PickOutRG>();
    }
    else
    {
      li = (List<PickOutRG>)Session["PickOutRG"];
    }

    if (!IsPostBack)
    {
      //初始化已選購
      Session["PickOut"] = null;
      //2:紅標
      GenProductList("2");
      //3:綠標
      GenProductList("3");
      //已選購紅配綠商品明細
      GenPickOutList();
    }
  }

  /// <summary>
  /// 取得商品資料
  /// <summary>
  private void GenProductList(string strRedGreen)
  {
    //計算分頁的筆數區間
    PageControl nav = strRedGreen == "2" ? this.Nav1 : this.Nav2;
    int pageSize = 3;
    int fromNo = 1 + pageSize * (nav.currentPageNumber - 1);
    int fromTo = fromNo + pageSize - 1;

    string strProductRG = (strRedGreen == "2" ? "ProductR" : "ProductG");
    Repeater rep = strRedGreen == "2" ? this.repeaterRed : this.repeaterGreen;

    B2C_MALL_GetProductList_2 ws = new B2C_MALL_GetProductList_2();
    ws.Url = ConfigurationManager.AppSettings["B2C_MALL_GetProductList_2"].ToString(); 
    string strJsonList = ws.B2C_MALL_GetProductList(CommonUtil.GetWebDevice(), HttpContext.Current.User.Identity.Name
        , Prod_Cat_ID, fromNo.ToString(), fromTo.ToString(), "1", strRedGreen, "1", "99999999");
    JObject jObj = JsonConvert.DeserializeObject<JObject>(strJsonList);
    if (jObj["Is_Valid"].ToString() == "Y")
    {
      //記錄讀取商品
      List<ProductRG> li = new List<ProductRG>();

      foreach (var ja in (JArray)jObj["ProductList_Ary"])
      {
        ProductRG pro = new ProductRG();
        pro.B2C_CODE = ja["B2C_CODE"].ToString();
        pro.ImagePath = ja["IMAGE_PATH_M"].ToString();
        pro.ProductName = ja["B2C_CODE_NAME"].ToString();
        pro.RedOrGreen = ja["R_or_G"].ToString();
        pro.ActPrice = Convert.ToDecimal(ja["ACT_PRICE"].ToString());
        pro.RedGreenPrice = Convert.ToDecimal(ja["RedGreenPrice"].ToString());
        li.Add(pro);
      }

      Session[strProductRG] = li;

      rep.DataSource = li;
      rep.DataBind();

      nav.TotalCount = jObj["Total_Count"].ToString();
      nav.PagesCount = Math.Ceiling((Convert.ToDecimal(jObj["Total_Count"]) / 3)).ToString();

      //配對規則暫存
      ViewState["RuleR"] = jObj["Rule"]["R"].ToString();
      ViewState["RuleG"] = jObj["Rule"]["G"].ToString();
      ViewState["Discount"] = jObj["Rule"]["Discount"].ToString();
    }
    else
    {
      rep.DataSource = null;
      rep.DataBind();
      nav.TotalCount = "0";
      nav.PagesCount = "0";
    }
    //不滿5頁的去除其頁數 by Adams
    nav.DisplayPageNumber();
  }

  // <summary>
  /// 已選購紅配綠商品明細
  /// <summary>
  private void GenPickOutList()
  {
    gvPcikOut.DataSource = li;
    gvPcikOut.DataBind();

    //計算已選購數量與費用

    int intR = 0;
    int intG = 0;
    decimal decActPrice = 0;
    decimal decFinalPrice = 0;
    if (li.Count > 0)
    {
      foreach (PickOutRG pic in li)
      {
        if (pic.RedOrGreen == "R")
        {
          intR += pic.Quantity;
        }
        else
        {
          intG += pic.Quantity;
        }
      }

      B2C_MALL_ORDER ws = new B2C_MALL_ORDER();
      ws.Url = ConfigurationManager.AppSettings["B2C_MALL_ORDER"].ToString(); 
      StringBuilder sbOrderList = new StringBuilder("[");
      int i = 0;
      foreach (PickOutRG pic in li)
      {
        if (i > 0)
        {
          sbOrderList.Append(",");
        }
        sbOrderList.Append("{\"B2C_CODE\":\"" + pic.B2C_CODE + "\"");
        sbOrderList.Append(",\"Smas_Code\":\"" + pic.SMAS_CODE + "\"");
        //館別(紅配綠固定為8傳給結帳的WS)
        sbOrderList.Append(",\"Prod_Cat_ID\":\"" + pic.Prod_Cat_ID + "\"");
        //Red=4，Green=5
        string strType = pic.RedOrGreen == "R" ? "4" : "5";
        sbOrderList.Append(",\"Type\":\"" + strType + "\"");
        sbOrderList.Append(",\"QTY\":\"" + pic.Quantity + "\"}");
        i++;
      }
      sbOrderList.Append("]");
      string strJson = ws.B2C_MALL_ValidateOrderInfo(CommonUtil.GetWebDevice(), HttpContext.Current.User.Identity.Name
          , "3", "3", "1", sbOrderList.ToString(), "", "", "", "", "", "", "2", "", "", "","");

      JObject jObj = JsonConvert.DeserializeObject<JObject>(strJson);
      if (jObj["Is_Valid"].ToString() == "Y")
      {
        var ja = jObj["pOrderSumList_Ary"];
        //單價總計(含稅)=已折扣後金額+折扣金額
        decActPrice = Convert.ToDecimal(ja["PriceSum"]) + Convert.ToDecimal(ja["discountSum"]);
        decFinalPrice = Convert.ToDecimal(ja["PriceSum"]);
      }
    }
    ltlQtyRed1.Text = intR.ToString("n0");
    ltlQtyGreen1.Text = intG.ToString("n0");
    ltlActPrice1.Text = decActPrice.ToString("n0");
    ltlTotalPrice1.Text = decFinalPrice.ToString("n0");
    
    ltlQtyRed2.Text = ltlQtyRed1.Text;
    ltlQtyGreen2.Text = ltlQtyGreen1.Text;
    ltlActPrice2.Text = ltlActPrice1.Text;
    ltlTotalPrice2.Text = ltlTotalPrice1.Text;
    
    int intRuleR = Convert.ToInt32(ViewState["RuleR"]);
    int intRuleG=Convert.ToInt32(ViewState["RuleG"]);
    int intMin = 0;
    //無產品不計算
    if (intRuleR > 0 & intRuleG>0)
    {
      intMin = (intR / intRuleR) < (intG / intRuleG) ? (intR / intRuleR) : (intG / intRuleG);
      //配對訊息
      ltlMsg1.Text = "紅標商品" + intRuleR.ToString() + "件";
      ltlMsg1.Text += "+ 綠標商品" + intRuleG.ToString() + "件";
      ltlMsg1.Text += "，可享" + (Convert.ToDouble(ViewState["Discount"]) * 10).ToString() + "折折扣";
    }
    int intActPriceR = intR - intRuleR * intMin;
    int intActPriceG = intG - intRuleG * intMin;
    if ((intR + intG) > 0)
    {
      string strMsg = "<br />";
      if (intActPriceR == 0 & intActPriceG == 0)
      {
        strMsg += "您已完成" + intMin.ToString() + "組紅配綠商品配對";
      }
      else if (intActPriceR > 0 & intActPriceG > 0)
      {
        strMsg += "您有 " + intActPriceR + " 件紅標與" + intActPriceG + " 件綠標商品未達折扣優惠價";
      }
      else if (intActPriceR > 0)
      {
        strMsg += "您有 " + intActPriceR + " 件紅標商品未達折扣優惠價";
      }
      else
      {
        strMsg += "您有 " + intActPriceG + " 件綠標商品未達折扣優惠價";
      }
      ltlMsg1.Text += strMsg;
    }
    ltlMsg2.Text = ltlMsg1.Text;    
  }

  /// <summary>
  /// 商品資料設定
  /// <summary>
  protected void repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
  {
    //由Detail取得規格資料(SMAS_CODE、Prd_Type、Storage_Qty)下拉選單進行設定
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
      B2C_MALL_GetProductList_2 ws = new B2C_MALL_GetProductList_2();
      ws.Url = ConfigurationManager.AppSettings["B2C_MALL_GetProductList_2"].ToString();
      string jsonString = ws.B2C_MALL_GetProductDetail(CommonUtil.GetWebDevice()
        , HttpContext.Current.User.Identity.Name, ((Literal)e.Item.FindControl("ltlID")).Text);
      JObject jObject = JsonConvert.DeserializeObject<JObject>(jsonString);

      if (jObject["Is_Valid"].ToString() == "Y")
      {
        JArray jAry = (JArray)jObject["Prd_Type_Ary"];
        DropDownList ddlQty = (DropDownList)e.Item.FindControl("ddlQty");
        Label lblQty = (Label)e.Item.FindControl("lblQty");
        DropDownList ddlPrdType = (DropDownList)e.Item.FindControl("ddlPrdType");
        HiddenField hfQty = (HiddenField)e.Item.FindControl("hfQty");
        HtmlTableRow trPrdType = (HtmlTableRow)e.Item.FindControl("trPrdType");
        string strCheckBoxID = ((Repeater)Sender).ID == "repeaterRed" ? "cbAddR" : "cbAddG";
        CheckBox cbAdd = (CheckBox)e.Item.FindControl(strCheckBoxID);
        ddlPrdType.DataSource = jAry;
        ddlPrdType.DataTextField = "Prd_Type";
        ddlPrdType.DataValueField = "SMAS_CODE";
        ddlPrdType.DataBind();
        //ddlPrdType.Items.Add("test111");
        //只有一種規格且無規格名稱隱藏該列
        if (jAry.Count == 1 && jAry[0]["Prd_Type"].ToString() == "")
        { 
          trPrdType.Attributes.Add("style","display:none");
        }
        StringBuilder sbJS = new StringBuilder();
        sbJS.AppendLine("$(document).ready(function () {");
        //規格變更事件
        sbJS.AppendLine(" $('#" + ddlPrdType.ClientID + "').change(function () {");
        sbJS.AppendLine("   var QtyArray=new Array();");
        int i = 0;
        foreach (var ja in jAry)
        {
          if (ja["Storage_Qty"].ToString() == "0")
          {
            sbJS.AppendLine("   QtyArray[" + i.ToString() + "]=0;");
            hfQty.Value="0";
          }
          else
          {
            sbJS.AppendLine("   QtyArray[" + i.ToString() + "]=100;");
            hfQty.Value = "1";
          }
          i++;
        }
        sbJS.AppendLine("   QtyArray[1]='100';");
        //規格變動
        //規格變動 - 清除選項
        sbJS.AppendLine("   $('#" + ddlQty.ClientID + " option').remove();");
        sbJS.AppendLine("   var intQty=QtyArray[$('#" + ddlPrdType.ClientID + "').find(':selected').index()];");
        sbJS.AppendLine("   if (intQty==0){");
        //規格變動 - 無庫存數量與加入CheckBox鎖定
        //sbJS.AppendLine("     $('#" + ddlQty.ClientID + "').append($('<option></option>').attr('value', '').text('已售完'));");
        sbJS.AppendLine("     $('#" + lblQty.ClientID + "').attr('style', 'display:display');");
        sbJS.AppendLine("     $('#" + ddlQty.ClientID + "').attr('disabled', 'disabled');");
        sbJS.AppendLine("     $('#" + ddlQty.ClientID + "').attr('style', 'display:none');");
        sbJS.AppendLine("     $('#" + cbAdd.ClientID + "').attr('disabled', 'disabled');");
        sbJS.AppendLine("   }");
        sbJS.AppendLine("   else{");
        sbJS.AppendLine("     $('#" + lblQty.ClientID + "').attr('style', 'display:none');");
        sbJS.AppendLine("     $('#" + ddlQty.ClientID + "').removeAttr('disabled');");
        sbJS.AppendLine("     $('#" + ddlQty.ClientID + "').removeAttr('style');");
        sbJS.AppendLine("     $('#" + cbAdd.ClientID + "').removeAttr('disabled');");
        sbJS.AppendLine("     for (i=1;i<=intQty;i++) {");
        sbJS.AppendLine("       $('#" + ddlQty.ClientID + "').append($('<option></option>').attr('value', i).text(i));");
        sbJS.AppendLine("     }");
        sbJS.AppendLine("   }");
        sbJS.AppendLine(" });");
        //數量變動
        sbJS.AppendLine(" $('#" + ddlQty.ClientID + "').change(function () {");
        sbJS.AppendLine("   $('#"+hfQty.ClientID+"').val($('#" + ddlQty.ClientID + "').find(':selected').val());");
        sbJS.AppendLine(" });");
        //觸發事件取得數量選項
        sbJS.AppendLine(" $('#" + ddlPrdType.ClientID + "').change();");
        sbJS.AppendLine("});");
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), ddlPrdType.ClientID, sbJS.ToString(), true);
      }
    }
  }

  /// <summary>
  /// 分頁設定設定
  /// <summary>
  protected void Nav1_OnPageSelected(object sender)
  {
    GenProductList("2");
    GenProductList("3");
  }

  /// <summary>
  /// 加入已選購紅配綠商品明細
  /// <summary>  
  protected void cbAdd_CheckedChanged(object sender, EventArgs e)
  {
    CheckBox cbAdd = (CheckBox)sender;
    cbAdd.Checked = false;
    Repeater rep = (cbAdd.ID == "cbAddR" ? this.repeaterRed : this.repeaterGreen);
    int intQty = 0;
    string strPrdType="";
    string strSMAS_CODE = "";
    //取得數量
    foreach (RepeaterItem ri in rep.Items)
    {
      CheckBox cbAddChecked = (CheckBox)ri.FindControl(cbAdd.ID);
      if (cbAddChecked.ClientID == cbAdd.ClientID)
      {
        intQty = Convert.ToInt32(((HiddenField)ri.FindControl("hfQty")).Value);
        strSMAS_CODE = ((DropDownList)ri.FindControl("ddlPrdType")).SelectedValue;
        strPrdType = ((DropDownList)ri.FindControl("ddlPrdType")).SelectedItem.Text;
      }
    }

    //確認是否已有所選商品(進行刪除)
    int i = 0;
    int intDel = -1;
    if (li.Count > 0)
    {
      foreach (PickOutRG pic in li)
      {
        if (pic.SMAS_CODE == strSMAS_CODE)
        {
          intDel = i;
          break;
        }
        i++;
      }
      if (intDel >= 0)
      {
        li.RemoveAt(intDel);
      }
    }

    string strProductRG = (cbAdd.ID == "cbAddR" ? "ProductR" : "ProductG");
    foreach (ProductRG pro in ((List<ProductRG>)Session[strProductRG]))
    {
      if (pro.B2C_CODE == cbAdd.ToolTip)
      { 
        PickOutRG po = new PickOutRG();
        po.SMAS_CODE = strSMAS_CODE;
        po.B2C_CODE = pro.B2C_CODE;
        po.ImagePath = pro.ImagePath;
        po.ProductName = pro.ProductName;
        po.RedOrGreen = pro.RedOrGreen;
        po.ActPrice = pro.ActPrice;
        po.RedGreenPrice = pro.RedGreenPrice;
        po.Quantity = intQty;
        po.Spec = strPrdType;
        string strType = pro.RedOrGreen == "R" ? "4" : "5";
        po.Type = strType;        
        li.Add(po);
        break;
      }
    }
    //儲存與讀取資料
    SaveAndLoad();
  }

  /// <summary>
  /// 已選購紅配綠商刪除
  /// <summary>
  protected void gvPcikOut_RowCommand(object sender, GridViewCommandEventArgs e)
  {
    if (e.CommandName == "RowDel")
    {
      int i = 0;
      foreach (PickOutRG pic in li)
      {
        if (pic.SMAS_CODE == e.CommandArgument.ToString())
        {
          break;
        }
        i++;
      }
      li.RemoveAt(i);
      //儲存與讀取資料
      SaveAndLoad();
    }
  }

  /// <summary>
  /// 儲存與讀取資料
  /// <summary>
  private void SaveAndLoad()
  {
    //記錄異動
    Session["PickOutRG"] = li;
    //已選購紅配綠商品明細
    GenPickOutList();
    //重新讀取紅配綠產品
    GenProductList("2");
    GenProductList("3");
  }

  /// <summary>
  /// 加入購物車
  /// <summary>
  protected void addCart_ServerClick(object sender, EventArgs e)
  {
    //加入購物車
    foreach (PickOutRG pic in li)
    {
      Server.Execute("~/Shopping/AddToCart.aspx?B2C_CODE=" + pic.B2C_CODE
          + "&SMAS_CODE=" + pic.SMAS_CODE + "&qty=" + pic.Quantity + "&catid=2&Type=" + pic.Type);
    }
    //清除已選購紅配綠商品明細
    Session["PickOutRG"] = null;
    Response.Redirect("ProductsListRedGreen.aspx");
  }

  /// <summary>
  /// 加入預選清單
  /// <summary>
  protected void addWishList_ServerClick(object sender, EventArgs e)
  {
    //加入預選清單
    foreach (PickOutRG pic in li)
    {
      Server.Execute("~/Shopping/AddToWishlist.aspx?B2C_CODE=" + pic.B2C_CODE
          + "&SMAS_CODE=" + pic.SMAS_CODE + "&qty=" + pic.Quantity + "&catid=2&Type=" + pic.Type);
    }
    //清除已選購紅配綠商品明細
    Session["PickOutRG"] = null;
    Response.Redirect("ProductsListRedGreen.aspx");
  }
  
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="NestedContent" runat="server">
  <script type="text/javascript">
    $(document).ready(function () {

      $('.PopDetail').click(function (event) {
        window.open($(this).attr("href"), 'PopDetail', 'width=750px;menubar=no,location=no,resizable=no,scrollbars=yes,status=no');
        event.preventDefault();
      });
      //設定scroll垂直位置
      $('html, body').scrollTop($('#<%= hfScroll.ClientID %>').val());
    });

    //記錄scroll垂直位置
    $(function () {
      $(window).scroll(function () {
        $('#<%= hfScroll.ClientID %>').val($(this).scrollTop());
      });
    });
  </script>
  <asp:HiddenField ID="hfScroll" runat="server" Value="0" />
  <div class="simple-banner">
    <a href="#">
      <img src="../Images/banners/SimpleBanner/Simple2.jpg" alt="紅配綠優惠" />
    </a>
  </div>
  <div class="breadcrumbs">
    <a href="../Home.aspx">首頁</a> /<a href="ProductsList.aspx?category=8">優惠情報 </a>/ <a href="#" class="current">紅配綠搭配</a>
  </div>
  <div class="share-tools r-pad" style="display:none">
    <!-- Social Button BEGIN -->
    <div class="social-network">
      <a href="javascript: void(window.open('http://www.facebook.com/share.php?u='.concat(encodeURIComponent(location.href)) ));" class="button_facebook" title="分享到facebook"></a>
      <a href="javascript: void(window.open('http://twitter.com/share?url='.concat(encodeURIComponent(location.href)) .concat('&text=') .concat(encodeURIComponent(document.title))));" class="button_twitter" title="分享到twitter"></a>
      <a href="javascript: void(window.open('http://www.plurk.com/?qualifier=shares&amp;status=' .concat(encodeURIComponent(location.href)) .concat(' ') .concat('(') .concat(encodeURIComponent(document.title)) .concat(')')));" class="button_plurk" title="分享到plurk"></a>
      <a href="javascript: void(window.open('http://v.t.sina.com.cn/share/share.php?title='.concat(encodeURIComponent(document.title)).concat('&url=').concat(encodeURIComponent(location.href))));" class="button_sinaweibo" title="分享到新浪微博"></a>
    </div>
  </div>
  <!-- #share -->
  <div class="display">
    <div class="display-left">
      <table>
        <tr>
          <td rowspan="2">已選購</td>
          <td rowspan="2">
            <img src="../Images/Icons/RightArrow.png" />
          </td>
          <td>紅標:</td>
          <td><strong class="red-text"><asp:Literal ID="ltlQtyRed1" runat="server"></asp:Literal></strong></td>
          <td>件</td>
        </tr>
        <tr>
          <td>綠標:</td>
          <td><strong class="green-text"><asp:Literal ID="ltlQtyGreen1" runat="server"></asp:Literal></strong></td>
          <td>件</td>
        </tr>
      </table>
    </div>

    <div class="display-right">
      <p>
        <span>原價:  <strong>$ <asp:Literal ID="ltlActPrice1" runat="server"></asp:Literal> 元</strong></span>
        優惠價:<label class="orange-text"> $ <asp:Literal ID="ltlTotalPrice1" runat="server"></asp:Literal></label>元
      </p>
      <p class="red-text">
        <%--您有一件紅標商品未達折扣優惠價--%>
        <asp:Literal ID="ltlMsg1" runat="server"></asp:Literal>
      </p>
    </div>
  </div>
  <!-- #display -->
  <div class="page-tools">
    <!-- Page Nav User Control -->
    <Page:Nav ID="Nav1" runat="server" OnOnPageSelected="Nav1_OnPageSelected" />
  </div>
  <div class="plus-products red">
    <h3>紅標商品區</h3>
    <div class="products-item-container">
      <asp:Repeater ID="repeaterRed" runat="server" OnItemDataBound="repeater_ItemDataBound">
        <ItemTemplate>
          <div class="products-item">
            <div class="image-container">
              <div class="sales"></div>
              <a href='<%# "ProductDetailPopup.aspx?B2C_CODE="+ Server.HtmlEncode(Eval("B2C_CODE").ToString()) %>' class="PopDetail">
                <img src='<%# Server.HtmlEncode(Eval("ImagePath").ToString()) %>' alt="#" />
              </a>
            </div>
            <div class="general-info">
              <div class="top-table">
                <p>
                  <%# Server.HtmlEncode(Eval("ProductName").ToString()) %>
                </p>
                <table>
                  <tr>
                    <th>特價</th>
                    <td><strong>$ <%# Server.HtmlEncode(Eval("ActPrice","{0:n0}").ToString()) %></strong></td>
                  </tr>
                </table>
              </div>
              <div class="bottom-table">
                <table>
                  <tr>
                    <th>數量</th>
                    <td>
                      <asp:Literal ID="ltlID" runat="server" Text='<%# Server.HtmlEncode(Eval("B2C_CODE").ToString()) %>' Visible="false"></asp:Literal>
                      <asp:HiddenField ID="hfQty" runat="server" Value="1" />
                      <asp:DropDownList ID="ddlQty" runat="server"></asp:DropDownList>
                      <asp:Label ID="lblQty" runat="server" Text="已售完"></asp:Label>
                    </td>
                    <td>
                      <asp:CheckBox ID="cbAddR" runat="server" ToolTip='<%# Server.HtmlEncode(Eval("B2C_CODE").ToString()) %>' OnCheckedChanged="cbAdd_CheckedChanged" AutoPostBack="true" />
                    </td>
                  </tr>
                  <tr id="trPrdType" runat="server">
                    <th>規格</th>
                    <td colspan="2">
                      <asp:DropDownList ID="ddlPrdType" runat="server"></asp:DropDownList>
                    </td>
                  </tr>
                </table>
              </div>
            </div>
          </div>
        </ItemTemplate>
      </asp:Repeater>
    </div>
  </div>
  <!-- #product-red -->
  <div class="plus-products green">
    <h3>綠標商品區</h3>
    <div class="products-item-container">
      <asp:Repeater ID="repeaterGreen" runat="server" OnItemDataBound="repeater_ItemDataBound">
        <ItemTemplate>
          <div class="products-item">
            <div class="image-container">
              <div class="sales"></div>
              <a href='<%# "ProductDetailPopup.aspx?B2C_CODE="+ Server.HtmlEncode(Eval("B2C_CODE").ToString()) %>' class="PopDetail">
                <img src='<%# Server.HtmlEncode(Eval("ImagePath").ToString()) %>' alt="#" />
              </a>
            </div>
            <div class="general-info">
              <div class="top-table">
                <p>
                  <%# Server.HtmlEncode(Eval("ProductName").ToString()) %>
                </p>
                <table>
                  <tr>
                    <th>特價</th>
                    <td><strong>$ <%# Server.HtmlEncode(Eval("ActPrice","{0:n0}").ToString()) %></strong></td>
                  </tr>
                </table>
              </div>
              <div class="bottom-table">
                <table>
                  <tr>
                    <th>數量</th>
                    <td>
                      <asp:Literal ID="ltlID" runat="server" Text='<%# Server.HtmlEncode(Eval("B2C_CODE").ToString()) %>' Visible="false"></asp:Literal>
                      <asp:HiddenField ID="hfQty" runat="server" Value="1" />
                      <asp:DropDownList ID="ddlQty" runat="server"></asp:DropDownList>
                      <asp:Label ID="lblQty" runat="server" Text="已售完"></asp:Label>
                    </td>
                    <td>
                      <asp:CheckBox ID="cbAddG" runat="server" ToolTip='<%# Server.HtmlEncode(Eval("B2C_CODE").ToString()) %>' OnCheckedChanged="cbAdd_CheckedChanged" AutoPostBack="true" />
                    </td>
                  </tr>
                  <tr id="trPrdType" runat="server">
                    <th>規格</th>
                    <td colspan="2">
                      <asp:DropDownList ID="ddlPrdType" runat="server"></asp:DropDownList>
                    </td>
                  </tr>
                </table>
              </div>
            </div>
          </div>
        </ItemTemplate>
      </asp:Repeater>
    </div>
  </div>
  <!-- #Product Green -->

  <div class="marge-bottom">
    <div class="liner"></div>
    <!-- Page Nav User Control -->
    <Page:Nav ID="Nav2" runat="server" OnOnPageSelected="Nav1_OnPageSelected" />

    <div class="marge-btn">
      <a class="blue-btn" href="#" id="addCart" runat="server" title="加入購物車" onserverclick="addCart_ServerClick">
        <img id="Img7" src="~/Images/Icons/Car.png" runat="server" />加入購物車
      </a>
      <%-- <a class="blue-btn" href="#">
                <img src="../Images/Icons/Car.png" />
                加入購物車</a>--%>
      <a class="blue-btn" href="#" id="addWishList" runat="server" onserverclick="addWishList_ServerClick">
        <img src="../Images/Icons/WishList.png" />加入預選清單
      </a>
    </div>
  </div>

  <!-- #marge-bottom-->

  <div class="my-list">
    <div class="display">
      <div class="display-left">
        <table>
          <tr>
            <td rowspan="2">已選購</td>
            <td rowspan="2">
              <img src="../Images/Icons/RightArrow.png" />
            </td>
            <td>紅標:</td>
            <td><strong class="red-text"><asp:Literal ID="ltlQtyRed2" runat="server"></asp:Literal></strong></td>
            <td>件</td>
          </tr>
          <tr>
            <td>綠標:</td>
            <td><strong class="green-text"><asp:Literal ID="ltlQtyGreen2" runat="server"></asp:Literal></strong></td>
            <td>件</td>
          </tr>
        </table>
      </div>

      <div class="display-right">
        <p>
          <span>原價:<strong>$ <asp:Literal ID="ltlActPrice2" runat="server"></asp:Literal>元</strong></span>
          優惠價: <label class="orange-text">$ <asp:Literal ID="ltlTotalPrice2" runat="server"></asp:Literal></label>元
        </p>
        <p class="red-text">
          <%--您有一件紅標商品未達折扣優惠價--%>
          <asp:Literal ID="ltlMsg2" runat="server"></asp:Literal>
        </p>
      </div>
    </div>

    <!--  start -->

    <div class="red-green-list">
      <div class="red-green-scroll-list">
        <asp:GridView ID="gvPcikOut" runat="server" AutoGenerateColumns="False" GridLines="Horizontal" Caption="已選購紅配綠商品明細" OnRowCommand="gvPcikOut_RowCommand">
          <Columns>
            <asp:TemplateField HeaderText="" HeaderStyle-CssClass="size6">
              <ItemTemplate>
                <span class='<%# Server.HtmlEncode(Eval("RedOrGreen").ToString()).Replace("R","red-box").Replace("G","green-box") %>'></span>
              </ItemTemplate>
              <ItemStyle Width="50px" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="商品圖">
              <ItemTemplate>
                <img src='<%# Server.HtmlEncode(Eval("ImagePath").ToString()) %>' alt="#" style="width: 50px" />
              </ItemTemplate>
              <ItemStyle Width="50px" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="商品名稱">
              <ItemTemplate>
                <%# Server.HtmlEncode(Eval("ProductName").ToString()) %>
              </ItemTemplate>
              <ItemStyle />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="金額">
              <ItemTemplate>
                <%# Server.HtmlEncode(Eval("ActPrice", "{0:$ #,##0}").ToString()) %>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="數量">
              <ItemTemplate>
                <%# Server.HtmlEncode(Eval("Quantity", "{0:#,##0}").ToString()) %>
              </ItemTemplate>
              <ItemStyle />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="規格">
              <ItemTemplate>
                <%# Server.HtmlEncode(Eval("Spec").ToString()) %>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="">
              <ItemTemplate>
                <asp:ImageButton ID="ibtnDel" runat="server" CommandName="RowDel" CommandArgument='<%# Server.HtmlEncode(Eval("SMAS_CODE").ToString()) %>' ImageUrl="~/Images/Icons/Delete.png" />
              </ItemTemplate>
              <ItemStyle />
            </asp:TemplateField>
          </Columns>
        </asp:GridView>
      </div>
    </div>

    <!--  End -->

  </div>
  <!-- #my-list -->

  <div class="go-to-top">
    <a href="#">回到頂端</a>
  </div>
  <!-- #gototop -->
</asp:Content>
